package agentes;

import cenario.Cenario;

public class Agente{

    private int row;
    private int column;
    private static String CENARIO = "cenario";

    public Agente(int column, int row) {
        setRow(row);
        setColumn(column);
    }

    public void andarAleatorio() {
        int random = (int) Math.floor((Math.random() * 3));
        switch (random) {
            case 0:
                andarCima(); break;
            case 1:
                andarBaixo(); break;
            case 2:
                andarDireita(); break;
            case 3:
                andarEsquerda(); break;
            default: break;
        }
    }

    public void andarBaixo() {
    	int varRow = this.row;
    	varRow++;
    	
    	//checa se row-- � > 0 e < maxrow
    	if(setRow(varRow)){
                varRow--;
                Cenario.setAgente(null, this.column, varRow);
    		Cenario.setAgente(this, this.column, this.row);
    	}
    }

    public void andarCima() {
    	int varRow = this.row;
    	varRow--;
    	
    	//checa se row-- � > 0 e < maxrow
    	if(setRow(varRow)){
                varRow++;
                Cenario.setAgente(null, this.column, varRow);
    		Cenario.setAgente(this, this.column, this.row);
    	}
    }

    public void andarDireita() {
    	int varColumn = this.column;
    	varColumn++;
    	
    	//checa se row-- � > 0 e < maxrow
    	if(setColumn(varColumn)){
                varColumn--;
                Cenario.setAgente(null, varColumn, this.row);
    		Cenario.setAgente(this, this.column, this.row);
    	}
    }

    public void andarEsquerda() {
    	int varColumn = this.column;
    	varColumn--;
    	
    	//checa se row-- > 0 e < maxrow e posicao esta vazia
    	if(setColumn(varColumn)){
    		
                varColumn++;
                Cenario.setAgente(null, varColumn, this.row);
    		Cenario.setAgente(this, this.column, this.row);
    	}
    }

    public int getRow() {
        return row;
    }

    public boolean setRow(int row) {
    	if(row >= 0 && row <= Cenario.MAXROW && Cenario.getAgente(this.column, row)==null){
    		this.row = row;
        	return true;
    	}
    	return false;
    }

    public int getColumn() {
        return column;
    }

    public boolean setColumn(int column) {
    	if(row >= 0 && row <= Cenario.MAXCOLUMN && Cenario.getAgente(column, this.row)==null){
    		this.column=column;
    		return true;
    	}    	
    	return false;
    }
}
